import React from 'react'
// ===================================================================== Temp
import SearchForm from '#cpt/temp/SearchForm'
import Table from '#cpt/temp/Table'
import Controls from '#cpt/temp/Controls'
// ===================================================================== global declare
const { $fn, $Lazy } = window
// ===================================================================== $Lazy
const Page 		= $Lazy.load(()=>import('#tp/page/page-container'))
const $cache 	= $Lazy.file(()=>import('#private/cache-api'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		pag: {},
		// 搜索表单列表
		forms : [
			{ label: '接收时间',		names: ['start_at','end_at'], 	type:'date-range', 	loading:true },
			{ label: '科室',			name: 'parent_project_id',		type:'select', 		loading:true,	idStr:'uuid' },
			{ label: '岗位',			name: 'project_id',				type:'select', 		loading:true},
			{ label: '检测项目',		name: 'kind_id',				type:'select', 		loading:true},
			{ label: '操作人',		name: 'operator_id',			type:'select',		loading:true },
			{ label: '姓名',			name: 'patient_name'	},
			// 增加导出和姓名、条码、医院、操作时间的查询条件 2021-9-27  --马婷
			{ label: '条码号',		name: 'spec_code'	},
			{ label: '医院名称',		name: 'hosp_id',				type:'select',		loading:true },
			{ label: '操作时间',		names: ['start_operation_time','end_operation_time'], 	type:'date-range', 	loading:true },
		]
	}
	
	query = { operation_type: 8 }
	
	componentDidMount(){
		this.getSelect()
		
		if(window.isInit){
			this.fetch()
		}
	}
	
	// 获取下拉数据
	getSelect = () => {
		const { forms } = this.state
	
		$cache.then( async f => {
			// 科室
			$fn.setRow( forms, 'parent_project_id', await f.getCache({ api:'ke_shi' }) )
			// 岗位
			$fn.setRow( forms, 'project_id', await f.getCache({ api:'gang_wei' }) )
			// 检测项目
			$fn.setRow( forms, 'kind_id', await f.getCache({ api:'project_name' }) )
			// 操作人
			$fn.setRow( forms, 'operator_id', await f.getCache({ api:'employee' }) )
			// 医院
			$fn.setRow( forms, 'hosp_id',  await f.getCache({ api:'hospital' }))
			this.setState({ forms })
		})
	}

	
	// paging
	fetch = () => $fn.fetch.call(this,'statistics/getUserBehaviorLists')
	
	// 表单
	cols = [
		{ title: '条码号', 		dataIndex: 'spec_code', 			...$fn.table.spec_code },
		{ title: '实验号', 		dataIndex: 'experiment_num', 		...$fn.table.exp_num },
		{ title: '姓名', 		dataIndex: 'patient_name',  		...$fn.table.name},
		{ title: '性别', 		dataIndex: 'sex', 					...$fn.table.sex },
		{ title: '年龄', 		dataIndex: 'age', 					...$fn.table.age },
		{ title: '标本类型', 	dataIndex: 'spec_type_name', 		width:120 },
		{ title: '接收时间', 	dataIndex: 'check_time',  			...$fn.table.time},
		{ title: '医院名称', 	dataIndex: 'hosp_name',  			width:200},
		{ title: '第三方医院', 	dataIndex: 'third_hosp_name',  		width:200},
		{ title: '检验科室', 	dataIndex: 'parent_project_name',  	width:150},
		{ title: '检验岗位', 	dataIndex: 'project_name',  		width:150},
		{ title: '自然项目', 	dataIndex: 'parent_kind_name',  	width:200},
		{ title: '检测项目', 	dataIndex: 'kind_name',  			width:200},
		{ title: '送检科室', 	dataIndex: 'department_name',  		width:180},
		{ title: '原因', 		dataIndex: 'operation_reason',  	width:200},
		{ title: '创建时间', 	dataIndex: 'created_at',  			...$fn.table.time},
		{ title: '操作时间', 	dataIndex: 'updated_at',  			...$fn.table.time},
		{ title: '操作人', 		dataIndex: 'operator_name',  		...$fn.table.name},
	]
	
	// 操作按钮
	controls = () => {
		return [
			Controls.exports.call(this,'statistics/getUserBehaviorLists',{label:'导出'}),	// 导出
		]
	}
	
	render(){
		return (
			<Page title='终止记录' controls={this.controls()}>
				{/* 搜索 */}
				{ SearchForm.call(this) }
				{/* 表格 */}
				{ Table.call(this, { type: -1, isInit: window.isInit} ) }
			</Page>
		)
	}
}

export default Index